home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / music_utilities / pt012.dms / pt012.adf / NoDelete / src / split_string.c < prev   
C/C++ Source or Header  |  1992-05-14  |  935b  |  49 lines

  1. extern long howmany;
  2. extern char *patterns[];
  3. extern void *AllocMem();
  4. void  split_string(string)
  5. char *string;
  6.  
  7. {
  8. long i=0, wc=0;
  9. char substr[20];
  10. substr[0]=0;
  11.  
  12. while(*string==' ' || *string == '\t')    /* skip leading blanks */
  13.     string++;
  14.  
  15. while(*string && wc<50)
  16.     {
  17.     while(*string != ' ' && *string != '\t' && *string != 0)
  18.         {
  19.         substr[i]=*string;
  20.       string++;
  21.       i++;
  22.         }
  23.    substr[i] = 0;
  24.     if(patterns[wc])
  25.         FreeMem(patterns[wc], strlen(patterns[wc]) + 1L);
  26.  
  27.     patterns[wc]=AllocMem(strlen(substr)+1L, MEMF_CLEAR);
  28.  
  29.     if(!patterns[wc])
  30.         quit("Could not allocate memory for patterns!\n");
  31.    else
  32.         strcpy(patterns[wc], substr);
  33.     wc++;
  34.     i=substr[0]=0;
  35.  
  36.     while(*string == ' ' || *string == '\t')
  37.         string++;
  38.     }
  39. #ifdef DEBUG
  40. Printf("I found %ld words in this line.\n", wc);
  41. #endif
  42. howmany=wc;    /* set extern wordcount variable */
  43. #ifdef DEBUG
  44. for(i=0; i<howmany; i++)
  45.    Printf("Word %ld: %s\n", i, patterns[i]);
  46. #endif
  47. return;
  48. }
  49.